package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WorkItem;
import com.ruoyi.system.service.IWorkItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;

/**
 * 重点工作Controller
 * 
 * @author ruoyi
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/api/work")
public class WorkItemController extends BaseController
{
    @Autowired
    private IWorkItemService workItemService;

    /**
     * 查询重点工作列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(WorkItem workItem)
    {
        startPage();
        List<WorkItem> list = workItemService.selectWorkItemList(workItem);
        TableDataInfo dataTable = getDataTable(list);

        
        return dataTable;
    }

    /**
     * 导出重点工作列表
     */
    @PreAuthorize("@ss.hasPermi('system:work:export')")
    @Log(title = "重点工作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkItem workItem)
    {
        List<WorkItem> list = workItemService.selectWorkItemList(workItem);
        ExcelUtil<WorkItem> util = new ExcelUtil<WorkItem>(WorkItem.class);
        util.exportExcel(response, list, "重点工作数据");
    }

    /**
     * 获取重点工作详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:work:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workItemService.selectWorkItemById(id));
    }

    /**
     * 新增重点工作
     */
    @PreAuthorize("@ss.hasPermi('system:work:add')")
    @Log(title = "重点工作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkItem workItem)
    {
        return toAjax(workItemService.insertWorkItem(workItem));
    }

    /**
     * 修改重点工作
     */
    @PreAuthorize("@ss.hasPermi('system:work:edit')")
    @Log(title = "重点工作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkItem workItem)
    {
        return toAjax(workItemService.updateWorkItem(workItem));
    }

    /**
     * 更新工作进度
     */
    @PreAuthorize("@ss.hasPermi('system:work:edit')")
    @Log(title = "更新工作进度", businessType = BusinessType.UPDATE)
    @PutMapping("/progress/{id}")
    public AjaxResult updateProgress(@PathVariable("id") Long id, @RequestBody WorkItem workItem)
    {
        workItem.setId(id);
        return toAjax(workItemService.updateWorkItem(workItem));
    }

    /**
     * 删除重点工作
     */
    @PreAuthorize("@ss.hasPermi('system:work:remove')")
    @Log(title = "重点工作", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workItemService.deleteWorkItemByIds(ids));
    }
}
